﻿@model UniTax.Models.TaxiModel

<script src="~/Scripts/jquery-ui-1.9.0.js"> </script>
<link href="~/Content/themes/base/jquery-ui.css" rel="stylesheet" />

<link href="~/Content/Modal.css" rel="stylesheet" />
<link href="~/Content/ImageArea.css" rel="stylesheet" />

<script src="~/Scripts/jquery.validate.min.js"> </script>
<script src="~/Scripts/jquery.validate.unobtrusive.min.js"> </script>
<script src="~/Scripts/jquery.imgareaselect.js"> </script>
<script src="~/Scripts/jquery.fancyupload.js"> </script>
    
<script>
    $(document).ready(function() {
        $('.modal_block').click(function(e) {
            $('#tn_select').empty();
            $('.modal_part').hide();
        });
        $('#modal_link').click(function(e) {
            $('.modal_part').show();
            var context = $('#tn_select').load('/Home/UploadImage', function() {
                initSelect(context);
            });
            e.preventDefault();
            return false;
        });
    });
</script>

<div class="modal_block modal_part"></div>
<div class="modal_dialog modal_part" id="tn_select"></div>

@using (Ajax.BeginForm("TaxiCreate", "Home", new AjaxOptions
    {
        UpdateTargetId = "ajaxContainer",
        OnBegin = "showWaitDiv",
        OnSuccess = "hideWaitDiv"
    }))
{
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true)

    <fieldset>
        <legend>Taxi</legend>
        <div class="editor-label">
            @Html.LabelFor(model => model.Name)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Name)
            @Html.ValidationMessageFor(model => model.Name)
        </div>
        <div>
            <label>Город: @Model.Town.Name</label>
        </div>
        <div>
            @Html.EditorFor(model => model.TownId) @*Для того чтобы форма получила id города*@
        </div>
        <div class="editor-label">
            @Html.LabelFor(model => model.License)
        </div>
        <div class="editor-field">
            @Html.TextBoxFor(model => model.License)
            @Html.ValidationMessageFor(model => model.License)
        </div>
        <div class="editor-field">
            @Html.LabelFor(model => model.Phones)
            <div id="phoneList">
            </div>
            <input type="button" onclick=" show_prompt(1) " value="Добавить" />
        </div>
        <div class="editor-field">
            @Html.LabelFor(model => model.ContactPhones)
            <div id="contactPhoneList">
            </div>
            <input type="button" onclick=" show_prompt(2) " value="Добавить" />
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.ContactName)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.ContactName)
            @Html.ValidationMessageFor(model => model.ContactName)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Functions)
        </div>
        <div id="functionList" class="editor-field">
            @foreach (var function in Model.Functions)
            {
                @Html.CheckBox("func_" + function.Id, new {@name = function.Id, @style = "margin-right:10px"})
                @Html.DisplayFor(p => function.Name)
                <br />
            }
        </div>

        <div class="editor-field">
            <input type="button" id="modal_link" value="Выбрать логотип"/>
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Raiting)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Raiting)
            @Html.ValidationMessageFor(model => model.Raiting)
        </div>

        <p>
            <input type="submit" value="Создать" />
        </p>
    </fieldset>
}

<div id="back">
    @Ajax.ActionLink("Назад к списку такси", "TaxiList", new {id = Model.TownId}, new AjaxOptions
        {
            UpdateTargetId = "ajaxContainer",
            OnBegin = "showWaitDiv",
            OnSuccess = "hideWaitDiv"
        }, new {@onclick = "DelDatepicker()"})
</div>


@section Scripts
{
    @Scripts.Render("~/bundles/jqueryval")
}

    
@*Календарь*@
<script>
    $(function() {
        $('#License').datepicker({
            firstDay: 1,
            changeMonth: true,
            changeYear: true
        });

        $("#License").datepicker("option", "showAnim", "slideDown");
        $("#License").datepicker("option", "dateFormat", "dd/mm/yy");
        $("#License").datepicker("setDate", "@ViewBag.Date");
    });

    /*function DelDatepicker() {
        $("#License").datepicker("destroy");
    }*/
</script>

@*Окно добавления телефона*@
<script>
    function show_prompt(type) {
        var phone = prompt("Введите номер телефона", "");
        if (phone != null && phone != "") {
            add_phone(phone, type);
        }
    }

    function add_phone(phone, type) {
        var list;
        if (type == 1)
            list = document.getElementById('phoneList');//если добавляeтся Phone
        else list = document.getElementById('contactPhoneList'); //если добавляeтся ContactPhone
        // новый элемент
        var input = document.createElement('input');
        input.setAttribute("value", phone);
        input.setAttribute("type", 'text');


        var counter = 1;
        if (type == 1) {
            while (true) {
                if (document.getElementById('phone_' + counter) == null) {
                    /*input.setAttribute("id", 'phone_' + counter);*/
                    input.setAttribute("name", 'phone_' + counter);
                    break;
                } else counter = counter + 1;
            }
        } else {
            while (true) {
                if (document.getElementById('contactPhone_' + counter) == null) {
                    /*input.setAttribute("id", 'contactPhone_' + counter);*/
                    input.setAttribute("name", 'contactPhone_' + counter);
                    break;
                } else counter = counter + 1;
            }
        }
        // добавление в конец
        list.appendChild(input);
    }
</script>